package com.yzt.dynamicmodule.activity;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.fastjson.JSONObject;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.luck.picture.lib.basic.IBridgePictureBehavior;
import com.luck.picture.lib.basic.PictureCommonFragment;
import com.luck.picture.lib.basic.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.SelectMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.yzt.dynamicmodule.GameManager;
import com.yzt.dynamicmodule.adapter.ActivityGameContentAdapter;
import com.yzt.dynamicmodule.adapter.ActivityGameInUserAdapter;
import com.yzt.dynamicmodule.databinding.ActivityGameInBinding;
import com.yzt.dynamicmodule.dialog.GameMoreDialog;
import com.yzt.dynamicmodule.dialog.GamePunishDialog;
import com.yzt.dynamicmodule.dialog.GamePunishOpenDialog;
import com.yzt.dynamicmodule.dialog.GameUserLessDialog;
import com.yzt.dynamicmodule.dialog.IndexShareDialog;
import com.yzt.dynamicmodule.utils.ShakeDetector;
import com.yzt.p_base.AppUtils;
import com.yzt.p_base.utils.SharedPreferenceUtil;
import com.yzt.p_base.utils.ToastUtil;
import com.yzt.redpack.RedPkgDetailActivity;
import com.yzt.redpack.dialog.GameRedOpenDialog;
import com.yzt.redpack.dialog.GameRedPkgDialog;
import com.yzt.redpack.GameTransHostActivity;
import com.yzt.dynamicmodule.R;
import com.yzt.zhuju.RXingUtils;
import com.yzt.zhuju.activity.BaseViewBindingActivity;
import com.yzt.zhuju.arouter.RouterMine;
import com.yzt.zhuju.arouter.RouterUser;
import com.yzt.zhuju.dialog.BaseDialog;
import com.yzt.zhuju.dialog.BottomBaseDialog;
import com.yzt.dynamicmodule.dialog.GameGiftDialog;
import com.yzt.zhuju.dialog.CenterBaseDialog;
import com.yzt.zhuju.network.AresSubscriber;
import com.yzt.zhuju.network.biz.BizLayer;
import com.yzt.zhuju.network.entity.dynamic.GameScriptBean;
import com.yzt.zhuju.network.entity.dynamic.RedPkgDetailBean;
import com.yzt.zhuju.network.entity.game.GameConversationBean;
import com.yzt.zhuju.network.entity.game.GameDetailBean;
import com.yzt.zhuju.network.entity.game.GameStartBean;
import com.yzt.zhuju.network.entity.game.GameUserListBean;
import com.yzt.zhuju.network.entity.message.RedPackageStatusInfo;
import com.yzt.zhuju.photoview.PhotoViewManager;
import com.yzt.zhuju.utils.ActivityManagerUtils;
import com.yzt.zhuju.utils.AppDialogUtil;
import com.yzt.zhuju.utils.BarUtils;
import com.yzt.zhuju.utils.DefaultCropFileEngine;
import com.yzt.zhuju.utils.FastClickUtils;
import com.yzt.zhuju.utils.GlideImageEngine;
import com.yzt.zhuju.utils.McImageCompressEngine;
import com.yzt.zhuju.widget.widget.ImageLoadManger;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：bobwang
 * 创建时间：2023-10-12 00:12:51
 * 描述：游戏中
 * 游戏剧本
 */
public class GameActivity extends BaseViewBindingActivity<ActivityGameInBinding> implements View.OnClickListener, IBridgePictureBehavior
        , GameManager.MessageCallBackOnCLickListener {

    private String activityId;

    /**
     * 游戏详情
     */
    private GameDetailBean gameDetailBean;

    private ActivityGameInUserAdapter adapterUser;

    private ActivityGameContentAdapter adapterContent;

    private ShakeDetector detector;

    private GameManager gameManager;

    /**
     * 是否是房主
     */
    boolean isHost = false;

    private PhotoViewManager photoViewManager;

    private boolean showShareDialog = false;

    ShakeDetector.OnShakeListener shakeListener = new ShakeDetector.OnShakeListener() {
        @Override
        public void onShake() {
            if (!showShareDialog) {
                showShareDialog = true;
                Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
                long[] pattern = {0, 500, 200, 500};
                vibrator.vibrate(pattern, -1);
                Bundle bundle = new Bundle();
                bundle.putString("extra_game_id", activityId);
                GamePunishOpenDialog dialog = (GamePunishOpenDialog) BaseDialog.showDialog(GameActivity.this, GamePunishOpenDialog.class, bundle);
                dialog.setOnDismissListener(new GamePunishOpenDialog.OnDismissListener() {
                    @Override
                    public void onDismiss() {
                        showShareDialog = false;
                    }
                });
            }
        }
    };

    public static void startSelf(Context activity, String extraId) {
        activity.startActivity(new Intent(activity, GameActivity.class).putExtra("extra_id", extraId));
    }

    @Override
    public boolean hideTitleBar() {
        return true;
    }

    @NonNull
    @Override
    public ActivityGameInBinding generateViewBinding() {
        return ActivityGameInBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        BarUtils.setStatusBarLightMode(this, true);
        BarUtils.setStatusBarAlpha(this, 0);
        ARouter.getInstance().inject(this);
        photoViewManager = PhotoViewManager.getInstance(AppUtils.getApp());
        activityId = getIntent().getStringExtra("extra_id");
        initRecycle();
        initListener();
        getDetail();
        getPlayUser();
        detector = new ShakeDetector(GameActivity.this);
        detector.bindShakeListener(shakeListener);
        gameManager = GameManager.getInstance();
        gameManager.initChatRoomActionListener();
        gameManager.initMsgCallback();
        gameManager.setMessageCallBackOnCLickListener(this);
    }

    @Override
    protected void onDestroy() {
        gameManager.leaveRoom();
        super.onDestroy();
        detector.unBindShakeListener(shakeListener);
    }

    /**
     * 加载列表
     */
    private void initRecycle() {
        // 用户头像
        viewBinding.recyclerAvatar.setLayoutManager(new GridLayoutManager(this, 8));
        adapterUser = new ActivityGameInUserAdapter();
        viewBinding.recyclerAvatar.setAdapter(adapterUser);
        adapterUser.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                GameUserListBean item = adapterUser.getItem(position);
                if (item.getType() == 0) {
                    RouterUser.PersonalDetailActivity(item.getUserId());
                }
            }
        });
        // 活动消息
        viewBinding.recyclerContent.setLayoutManager(new LinearLayoutManager(this));
        adapterContent = new ActivityGameContentAdapter();
        viewBinding.recyclerContent.setAdapter(adapterContent);
        adapterContent.addChildClickViewIds(R.id.img_game_img, R.id.ll_red_package_container, R.id.img_temp_cover);
        adapterContent.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {

                GameConversationBean bean = adapterContent.getItem(position);

                if (view.getId() == R.id.img_game_img) {
                    List<String> list = new ArrayList<>();
                    list.add(bean.getPicUrl());
                    photoViewManager.showPhotoView(view, list, position);
                }
                if (view.getId() == R.id.ll_red_package_container) {

                    if (bean.getRedPackageType() == 2) {
                        if (!bean.getTargetUserId().equals(RXingUtils.getPersonDetail().getUserBasic().getUserId())) {
                            return;
                        }
                    }

                    BizLayer.getInstance().getMessageModule().getRedPkgStatus(bean.getRedPacketId(), new AresSubscriber<RedPackageStatusInfo>() {
                        @Override
                        protected void onSuccess(RedPackageStatusInfo redBean) {
                            //红包状态 [ 0：未领取，1：过期，2：已领 ]
                            if (redBean.getRedPackageStatus() == 0) {
                                // 红包封面
                                BizLayer.getInstance().getDynamicModule().getRedPacketInfo(bean.getRedPacketId(), new AresSubscriber<RedPkgDetailBean>() {
                                    @Override
                                    protected void onSuccess(RedPkgDetailBean redPkgInfo) {
                                        FragmentActivity topActivity = ActivityManagerUtils.getInstance().getTopActivity();
                                        Bundle bundle = new Bundle();
                                        bundle.putParcelable("extra_data", redPkgInfo);
                                        bundle.putString("extra_targetId", bean.getTargetUserId());
                                        GameRedOpenDialog.showDialog(topActivity, GameRedOpenDialog.class, bundle);
                                        bean.setReceive(true);
                                        adapterContent.notifyItemChanged(position);
                                    }
                                });
                            } else if (redBean.getRedPackageStatus() == 1) {
                                ToastUtil.showMessage("红包已过期");
                            } else {
                                FragmentActivity topActivity = ActivityManagerUtils.getInstance().getTopActivity();
                                Intent intent = new Intent(topActivity, RedPkgDetailActivity.class);
                                intent.putExtra("extra_id", bean.getRedPacketId());
                                topActivity.startActivity(intent);
                                bean.setReceive(true);
                                adapterContent.notifyItemChanged(position);
                            }
                        }
                    });
                }
                if (view.getId() == R.id.img_temp_cover) {
                    RouterMine.VideoPlayActivity("2", bean.getGameVideoUrl());
                }
            }
        });
    }

    /**
     * 初始化视图
     */
    private void initListener() {
        viewBinding.imgBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AppDialogUtil.showNoTitleDialog(GameActivity.this, "你确定要退出房间吗？", "取消", "确定", new AppDialogUtil.DialogClickInterface() {
                    @Override
                    public void onCancelClick() {

                    }

                    @Override
                    public void onSureClick() {
                        JSONObject json = new JSONObject();
                        json.put("activityId", activityId);
                        BizLayer.getInstance().getDynamicModule().quitRoom(json, new AresSubscriber<Object>() {
                            @Override
                            protected void onSuccess(Object bean) {
                                finish();
                            }
                        });
                    }
                });
            }
        });
        viewBinding.imgScript.setOnClickListener(this);
        viewBinding.imgMore.setOnClickListener(this);
        viewBinding.tvSelectScript.setOnClickListener(this);
        viewBinding.imgEmoji.setOnClickListener(this);
        viewBinding.imgCamera.setOnClickListener(this);
        viewBinding.imgPhoto.setOnClickListener(this);
        viewBinding.imgGift.setOnClickListener(this);
        viewBinding.imgRedPkg.setOnClickListener(this);
        viewBinding.imgPunish.setOnClickListener(this);
        viewBinding.imgGameNextLevel.setOnClickListener(this);
        viewBinding.tvContinueSelectScript.setOnClickListener(this);
        viewBinding.tvEndGame.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        if (FastClickUtils.isFastClick()) {
            return;
        }

        Intent intent;
        if (v.getId() == R.id.img_script) {
            // 查看剧本
            intent = new Intent(this, GameScriptListActivity.class);
            intent.putExtra("extra_id", activityId);
            intent.putExtra("extra_host", isHost);
            startActivity(intent);
        }
        if (v.getId() == R.id.img_more) {
            // 更多
            Bundle bundle = new Bundle();
            bundle.putBoolean("isHost", isHost);
            GameMoreDialog dialog = (GameMoreDialog) BottomBaseDialog.showDialog(this, GameMoreDialog.class, bundle);
            dialog.setListener(new GameMoreDialog.OnSelectOnClickListener() {
                @Override
                public void onTranHost() {
                    Intent intent = new Intent(GameActivity.this, GameTransHostActivity.class);
                    intent.putExtra("extra_type", 1);
                    intent.putExtra("extra_id", activityId);
                    startActivityForResult(intent, 2);
                }

                @Override
                public void onReport() {
                    Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + "110"));
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }
            });
        }
        if (v.getId() == R.id.tv_select_script || v.getId() == R.id.tv_continue_select_script) {
            // 选择剧本
            intent = new Intent(this, GameScriptListActivity.class);
            intent.putExtra("extra_id", activityId);
            intent.putExtra("extra_host", isHost);
            startActivityForResult(intent, 1);
        }

        if (v.getId() == R.id.tv_end_game) {
            // 结束游戏
            endGame();
        }
        if (v.getId() == R.id.img_game_next_level) {
            // 下一关
            gameNextLevel();
        }

        if (v.getId() == R.id.img_emoji) {
            // 表情
        }
        if (v.getId() == R.id.img_camera) {
            // 拍照
            openCamera();
        }
        if (v.getId() == R.id.img_photo) {
            // 选择照片
            selectImage();
        }
        if (v.getId() == R.id.img_gift) {
            // 礼物弹窗
            giftDialog();
        }
        if (v.getId() == R.id.img_red_pkg) {
            // 发红包
            sendRedPkg();
        }
        if (v.getId() == R.id.img_punish) {
            // 惩罚卡
            punishDialog();
        }
    }

    /**
     * 惩罚卡
     */
    private void punishDialog() {
        Bundle bundle = new Bundle();
        bundle.putString("extra_game_id", activityId);
        GameGiftDialog.showDialog(this, GamePunishDialog.class, bundle);
    }

    /**
     * 选择图片
     */
    private void selectImage() {
        PictureSelector.create(this).openGallery(SelectMimeType.ofImage()).setImageEngine(GlideImageEngine.Companion.getInstance()).setCompressEngine(McImageCompressEngine.Companion.getInstance()).setCropEngine(new DefaultCropFileEngine()).setMaxSelectNum(1).setMaxVideoSelectNum(1).isDirectReturnSingle(true).isDisplayCamera(false).isOpenClickSound(false).isFastSlidingSelect(true).isPreviewFullScreenMode(true).isPreviewZoomEffect(true).isPreviewImage(true).isMaxSelectEnabledMask(true).isGif(false).forResult(PictureConfig.CHOOSE_REQUEST);
    }

    /**
     * 拍照
     */
    private void openCamera() {
        PictureSelector.create(this).openCamera(SelectMimeType.ofImage()).setCompressEngine(McImageCompressEngine.Companion.getInstance()).forResult();
    }

    /**
     * 礼物弹窗
     */
    private void giftDialog() {
        Bundle bundle = new Bundle();
        bundle.putString("extra_game_id", activityId);
        GameGiftDialog.showDialog(this, GameGiftDialog.class, bundle);
    }

    /**
     * 发红包
     */
    private void sendRedPkg() {
        Bundle bundle = new Bundle();
        bundle.putInt("extra_user_count", 10);
        bundle.putString("extra_game_id", activityId);
        bundle.putInt("extra_scenario_type", 2);
        GameRedPkgDialog.showDialog(this, GameRedPkgDialog.class, bundle);
    }

    /**
     * 获取详情
     */
    public void getDetail() {
        JSONObject json = new JSONObject();
        json.put("activityId", activityId);
        BizLayer.getInstance().getDynamicModule().getGameDetail(json, new AresSubscriber<GameDetailBean>() {
            @Override
            protected void onSuccess(GameDetailBean bean) {
                gameDetailBean = bean;
                gameManager.setRongRoomId(gameDetailBean.getRongRoomId());
                gameManager.joinRoom();
                loadRoomInfo(bean);
            }
        });
    }

    /**
     * 刷新用户
     */
    private void getPlayUser() {
        JSONObject json = new JSONObject();
        json.put("activityId", activityId);
        json.put("oneself", true);
        BizLayer.getInstance().getDynamicModule().getGamePlayUser(json, new AresSubscriber<GameDetailBean>() {
            @Override
            protected void onSuccess(GameDetailBean bean) {
                ArrayList<GameUserListBean> listUser = new ArrayList<>();
                listUser.add(new GameUserListBean(1, ""));
                if (bean.getList().size() > 6) {
                    listUser.addAll(bean.getList().subList(0, 6));
                } else {
                    listUser.addAll(bean.getList());
                }
                listUser.add(new GameUserListBean(2, String.valueOf(bean.getList().size())));
                adapterUser.setList(listUser);
            }
        });
    }

    /**
     * 结束活动
     */
    private void endGame() {
        if (gameDetailBean.isHosted()) {
            JSONObject json = new JSONObject();
            json.put("activityId", activityId);
            BizLayer.getInstance().getDynamicModule().endGame(json, new AresSubscriber<Object>() {
                @Override
                protected void onSuccess(Object object) {
                    showToast("活动已结束!");
                    finish();
                }
            });
        }
    }

    /**
     * 加载房间状态
     */
    private void loadRoomInfo(GameDetailBean bean) {

        // 教学弹窗
        boolean firstJoin = SharedPreferenceUtil.getInstance().getValue("first_join_game", true);
        if (firstJoin) {
            SharedPreferenceUtil.getInstance().putValue("first_join_game", false);
            viewBinding.flStudy.setVisibility(View.VISIBLE);
            if (isHost) {
                viewBinding.imgStudy.setImageResource(R.mipmap.icon_game_in_study_host);
            } else {
                viewBinding.imgStudy.setImageResource(R.mipmap.icon_game_in_study_user);
            }
            viewBinding.flStudy.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    viewBinding.flStudy.setVisibility(View.GONE);
                }
            });
        }

        // 基础数据
        ImageLoadManger.loadIv(GameActivity.this, bean.getCover(), viewBinding.imgGameAvatar);
        viewBinding.tvGameName.setText(bean.getActivitySubject());
        isHost = bean.isHosted();

        //活动状态 [ 0：未付款(创建活动为我付款时候)，10：未开始，20：进行中，30：活动结束，40：活动取消 ]
        if (bean.getActivityStatus() == 10) {
            viewBinding.llGameNotStart.setVisibility(View.VISIBLE);
            if (isHost) {
                viewBinding.tvSelectScript.setVisibility(View.VISIBLE);
                viewBinding.tvGameNotStart.setText("开始游戏前请先");
            } else {
                viewBinding.tvSelectScript.setVisibility(View.GONE);
                viewBinding.tvGameNotStart.setText("游戏未开始，等待主持人开始游戏");
            }
        } else {
            viewBinding.llGameNotStart.setVisibility(View.GONE);
        }

        if (bean.getActivityStatus() == 20) {
            viewBinding.llGameNotStart.setVisibility(View.VISIBLE);
            viewBinding.tvGameNotStart.setText("游戏进行中");
            viewBinding.tvSelectScript.setVisibility(View.GONE);
            if (isHost) {
                if (bean.isHaveNext()) {
                    viewBinding.imgGameNextLevel.setVisibility(View.VISIBLE);
                    viewBinding.llContinueSelectScript.setVisibility(View.GONE);
                } else {
                    viewBinding.imgGameNextLevel.setVisibility(View.GONE);
                    viewBinding.llContinueSelectScript.setVisibility(View.VISIBLE);
                }
            }
        }

        if (bean.getActivityStatus() == 30) {
            showToast("活动已结束");
            finish();
        }

        if (bean.getActivityStatus() == 40) {
            showToast("活动已取消");
            finish();
        }
    }

    /**
     * 下一关游戏
     */
    private void gameNextLevel() {
        if (gameDetailBean.isHosted()) {
            JSONObject json = new JSONObject();
            json.put("activityId", activityId);
            BizLayer.getInstance().getDynamicModule().gameNextLevel(json, new AresSubscriber<GameDetailBean>() {
                @Override
                protected void onSuccess(GameDetailBean bean) {
                    if (bean.isHaveNext()) {
                        viewBinding.imgGameNextLevel.setVisibility(View.VISIBLE);
                        viewBinding.llContinueSelectScript.setVisibility(View.GONE);
                    } else {
                        viewBinding.imgGameNextLevel.setVisibility(View.GONE);
                        viewBinding.llContinueSelectScript.setVisibility(View.VISIBLE);
                    }
                }
            });
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && resultCode == RESULT_OK) {
            // 选择剧本
            GameScriptBean gameScriptBean = data.getParcelableExtra("extra_data");
            if (gameScriptBean != null) {
                setScript(gameScriptBean.getGameId());
            }
        }
        if (requestCode == 2 && resultCode == RESULT_OK) {
            // 更换主持人
            String uId = data.getStringExtra("extra_data");
            exchangeHost(uId);
        }

        if (requestCode == PictureConfig.CHOOSE_REQUEST) {
            if (data != null) {
                ArrayList<LocalMedia> result = PictureSelector.obtainSelectorList(data);
                for (LocalMedia bean : result) {
                    String picturePath = bean.getRealPath();
                    gameManager.sendImg(picturePath);
                }
            }
        }
    }

    /**
     * 设置剧本 - 开始游戏
     */
    private void setScript(int gameId) {
        JSONObject json = new JSONObject();
        json.put("activityId", activityId);
        json.put("gameId", gameId);
        BizLayer.getInstance().getDynamicModule().scriptSelect(json, new AresSubscriber<GameStartBean>() {
            @Override
            protected void onSuccess(GameStartBean bean) {
                if (bean.isHavePopup()) {
                    GameUserLessDialog dialog = (GameUserLessDialog) CenterBaseDialog.showDialog(GameActivity.this, GameUserLessDialog.class);
                    dialog.setListener(new GameUserLessDialog.OnSelectOnClickListener() {
                        @Override
                        public void onController(int type) {
                            if (type == 1) {
                                // 邀请其他玩家参与
                                IndexShareDialog share = (IndexShareDialog) BaseDialog.showDialog(GameActivity.this, IndexShareDialog.class);
                                share.setListener(type1 -> ToastUtil.showMessage("分享"));
                            }
                            if (type == 2) {
                                // 继续等待玩家
                                dialog.dismissAllowingStateLoss();
                            }
                            if (type == 3) {
                                // 取消当前游戏并重新发起
                                JSONObject json = new JSONObject();
                                json.put("activityId", activityId);
                                BizLayer.getInstance().getDynamicModule().cancelGame(json, new AresSubscriber<Object>() {
                                    @Override
                                    protected void onSuccess(Object bean) {
                                        showToast("取消成功");
                                        dialog.dismissAllowingStateLoss();
                                        finish();
                                    }
                                });

                            }
                        }
                    });
                } else {
                    showToast("游戏开始～");
                    getDetail();
                }
            }
        });
    }

    /**
     * 更换主持人
     */
    private void exchangeHost(String uid) {
        JSONObject json = new JSONObject();
        json.put("activityId", activityId);
        json.put("userId", uid);
        BizLayer.getInstance().getDynamicModule().exchangeHost(json, new AresSubscriber<Object>() {
            @Override
            protected void onSuccess(Object bean) {
                showToast("主持人更换成功");
                getDetail();
            }
        });
    }

    @Override
    public void onSelectFinish(PictureCommonFragment.SelectorResult result) {
        if (result.mResultData != null) {
            if (result.mResultData.getExtras() != null) {
                if (result.mResultData.getExtras().get("extra_result_media") != null) {
                    ArrayList<LocalMedia> list = (ArrayList<LocalMedia>) result.mResultData.getExtras().get("extra_result_media");
                    if (!list.isEmpty()) {
                        String path = list.get(0).getRealPath();
                        gameManager.sendImg(path);
                    }
                }
            }
        }
    }

    @Override
    public void onMessageCallBackConversation(GameConversationBean bean) {
        adapterContent.addData(bean);
        viewBinding.recyclerContent.scrollToPosition(adapterContent.getData().size() - 1);
//                PUNISH_CARD("OCM:GamePunishCard", "惩罚牌"),
//                GAME_RED_PACKET("OCM:GameRedPacket", "红包"),
//                GAME_RED_PACKET_OPEN("OCM:GameRedPacketOpen", "红包领取通知"),
//                GAME_GIFT("OCM:GameGift", "礼物"),
//                GAME_NEXT_MISSION("OCM:NextMission", "下一关"),
        if (bean.getMsgType().equals("OCM:NextMission")) {
            if (bean.isLasted() && gameDetailBean.isHosted()) {
                viewBinding.llContinueSelectScript.setVisibility(View.VISIBLE);
                viewBinding.imgGameNextLevel.setVisibility(View.GONE);
            }
        }
    }

    @Override
    public void onMessageCallBackNotify(GameConversationBean bean) {
//                ROOM_JOIN("OCM:roomJoin", "进入房间"),
//                ROOM_LEAVE("OCM:roomLeave", "离开房间"),
//                ROOM_KICK("OCM:roomKick", "踢出房间"),
//                GAME_OVER("OCM:GameOver", "结束游戏"),
//                GAME_QUIT("OCM:GameQuit", "退出游戏"),
//                GAME_CHANGE_ROLE("OCM:GameChangeRole", "切换主持人"),
//                GAME_START("OCM:GameStart", "开始游戏"),

        if (bean.getMsgType().equals("OCM:GameStart")) {
            getDetail();
        }
        if (bean.getMsgType().equals("OCM:roomJoin")) {

        }
        if (bean.getMsgType().equals("OCM:roomLeave")) {

        }
        if (bean.getMsgType().equals("OCM:roomKick")) {

        }
        if (bean.getMsgType().equals("OCM:GameOver")) {
            getDetail();
        }
        if (bean.getMsgType().equals("OCM:GameQuit")) {

        }
        if (bean.getMsgType().equals("OCM:GameChangeRole")) {
            if (bean.getNewEmceeUserId().equals(RXingUtils.getPersonDetail().getUserBasic().getUserId())
                    || bean.getSendUserId().equals(RXingUtils.getPersonDetail().getUserBasic().getUserId())) {
                getDetail();
            }
        }
    }
}
